﻿using DrawableObjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.Xna.Framework;
using GlobalGameClasses;
using Serialization;
using System.Collections.Generic;

namespace SirianTestEnvironment
{
    
    
    /// <summary>
    ///Dies ist eine Testklasse für "CameraTest" und soll
    ///alle CameraTest Komponententests enthalten.
    ///</summary>
    [TestClass()]
    public class CameraTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Ruft den Testkontext auf, der Informationen
        ///über und Funktionalität für den aktuellen Testlauf bietet, oder legt diesen fest.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional attributes for testing

        /// <summary>
        /// Initializes the required attributes for the test methods of this test class.
        /// </summary>
        /// <param name="testContext"></param>
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            TimeSpan totalGameTime = new TimeSpan(0, 0, 0, 0, 5000);
            TimeSpan elapsedGameTime = new TimeSpan(0, 0, 0, 0, 100);
            GameTime gameTime = new GameTime(totalGameTime, elapsedGameTime);

            GlobalGameValues.Values.gameTime = gameTime;
        }

        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            GlobalGameValues.Values.achievementsUnlocked = new List<Achievement>();
            GlobalGameValues.Values.content = new ContentCollection();
            GlobalGameValues.Values.difficulty = null;
            GlobalGameValues.Values.errorWriter = null;
            GlobalGameValues.Values.gameTime = new GameTime();
            GlobalGameValues.Values.GlobalStrings = new StringContainer();
            GlobalGameValues.Values.graphicsDevice = null;
            GlobalGameValues.Values.score = new InterfaceComponents.HUDWrapper<int>(new List<InterfaceComponents.HUDComponent>());
            GlobalGameValues.Values.soundPlayer = null;
            GlobalGameValues.Values.spriteBatch = null;
            GlobalGameValues.Values.volume_Music = 0;
            GlobalGameValues.Values.volume_soundEffect = 0;
        }

        #endregion


        /// <summary>
        ///Test for "Update"
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            Vector3 position = new Vector3(0, 1, 1);
            Vector3 startPosition = position;
            Vector3 target = Vector3.Zero;
            float movingSpeed = 2.0f;
            Vector3 movedPosition = position + new Vector3(0, 0, movingSpeed * GlobalGameValues.SPEEDFACTOR * (float)GlobalGameValues.Values.gameTime.ElapsedGameTime.TotalMilliseconds);

            Camera camera = new Camera(position, target, movingSpeed);
            camera.Update();

            Assert.AreEqual(Vector3.Distance(camera.position, startPosition), camera.distanceToStart);
            Assert.AreEqual(movedPosition, camera.position1);
        }

        
    }
}
